<div class="portlet">
  <div class="portlet-header">
    <h1><%=t ".title"%></h1>
  </div>

  <div class="portlet-content">
    <% form_tag contacts_path, :method => 'get' do %>
      <table style="border:0px">
        <tr>
          <td> <%= label_tag t('activerecord.attributes.contact.last_name') %> </td>
          <td colspan="2"> <%= text_field_tag :search_last_name, params[:search_last_name] %> </td>
        </tr>
        <tr>
          <td> <%= label_tag t('activerecord.attributes.contact.reference') %> </td>
          <td> <%= select_tag(:reference_class,options_for_select(@collection_reference_class.map {|u| [t(u),u]}, @reference_class)) %> </td>
          <td>
            <div id="reference_text"> <%= render :partial=>'reference_text' , :layout=>false %></div>
          </td>
          <td> <%= submit_tag t('btn_search'), :name => nil %> </td>
        </tr>
      </table>
    <% end %>

    <%= observe_field :reference_class,
      :frequency => 1,
      :update => 'reference_text',
      :url => {:controller => :contacts, :action => :show_reference_text},
      :with => "'reference_class='+value"%>

    <div class="line-label">
      <%= page_entries_info(@contacts) %>
    </div>

    <% if @contacts.size > 0 %>
      <% paginated_section(@contacts, options_will_paginate) do %>

        <table>
          <thead>
            <tr>
              <th><%=t('activerecord.attributes.contact.last_name')%></th>
              <th><%=t('activerecord.attributes.contact.first_name')%></th>
              <th><%=t('activerecord.attributes.contact.email')%></th>
              <th><%=t('activerecord.attributes.contact.client')%></th>
              <th colspan="3"><%= t('title_actions') %></th>
            </tr>
          </thead>

          <tbody>
            <% @contacts.each do |contact| %>
              <tr>
                <td><%=h contact.last_name %></td>
                <td><%=h contact.first_name %></td>
                <td><%=h contact.email %></td>
                    <% if contact.reference.nil? %>
                            <td></td>
                    <% else %>
                      <% if contact.reference_type == 'People' %>
                        <td><%=h "#{t('activerecord.models.people')}: #{contact.reference.last_name}, #{contact.reference.first_name}"%></td>
                      <% end %>
                      <% if contact.reference_type == 'Bookshop' %>
                        <td><%=h "#{t('activerecord.models.bookshop')}: #{contact.reference.name}"%></td>
                      <% end %>
                      <% if contact.reference_type == 'BookshopDepartment' %>
                        <td><%=h "#{t('activerecord.models.bookshop')}: #{contact.reference.bookshop.name} - #{t('activerecord.models.bookshop_department')}: #{contact.reference.name}"%></td>
                      <% end %>
                      <% if contact.reference_type == 'Institute' %>
                        <td><%=h "#{t('activerecord.models.institute')}: #{contact.reference.name}"%></td>
                      <% end %>
                      <% if contact.reference_type == 'Publisher' %>
                        <td><%=h "#{t('activerecord.models.publisher')}: #{contact.reference.name}"%></td>
                      <% end %>
                      <% if contact.reference_type == 'Library' %>
                        <td><%=h "#{t('activerecord.models.institute')}: #{contact.reference.institute.name} - #{t('activerecord.models.library')}: #{contact.reference.name}"%></td>
                      <% end %>
                      <% if contact.reference_type == 'LibraryDepartment' %>
                        <td><%=h "#{t('activerecord.models.institute')}: #{contact.reference.library.institute.name} - #{t('activerecord.models.library')}: #{contact.reference.library.name} - #{t('activerecord.models.library_department')}: #{contact.reference.name}"%></td>
                      <% end %>

                    <% end %>

                <td class="action"><%= link_to t('btn_show'), contact %></td>
                <td class="action"><%= link_to t('btn_edit'), edit_contact_path(contact) %></td>
                <td class="action"><%= link_to t('btn_destroy'), contact, :confirm => t('msg_sure_destroy?'), :method => :delete %></td>
              </tr>
            <% end %>
          </tbody>
        </table>
      <% end %>
    <% end %>

    <div class="line-links">
      <%= link_to t('contacts.index.btn_new_contact'), new_contact_path %>
    </div>
  </div>

  <div class="portlet-footer">
  </div>
</div>